<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        #app{
            width: 500px;
            height: 100%;
            padding: 10px;
            margin: auto;
        }

        h1 {
            text-align: center;
            border-bottom: 1px solid #dbdbdb;
            margin-bottom: 10px;
        }

        body {
            background-color: #efefef;
        }

        .grit>div {
            display: grid;
            grid-template-columns: auto auto;
            justify-content: center;
            width: 100%;
        }

        .box {
            width: 200px;
            background-color: #ffffff;
            margin: 10px;
            border-radius: 10px;
            display: flex;
            flex-direction: column;
            position: relative;
        }

        .box img {
            width: 100%;
        }

        .box h2 {
            font-size: 14px;
            font-weight: 400;
            width: 80%;
            margin-left: 10%;
            margin-top: 10px;
            margin-right: 10%;
        }

        .box>div {
            position: absolute;
            bottom: 5%;
            width: 80%;
            left: 10%;
            display: flex;
            align-items: center;
            margin: 5px;
        }

        .box .sp1 {
            color: red;
            font-size: 17px;
        }

        .box .sp2 {
            font-size: 12px;
            color: rgb(19, 17, 17);
        }

        .box a {
            color: #c2c2c2;
            font-size: 12px;
            font-weight: 200;
            padding: 10px;
            border-radius: 10px;
            text-decoration: none;
            height: 15px;
            position: absolute;
            right: 0;
        }
    </style>
</head>

<body>
    <div id="app">
        <h1>  猜你喜欢  </h1>
        <div class="grit" @click="poiu">
            <box></box>
        </div>
    </div>


    <script src="./js/vue.js"></script>
    <template id="box">
        <div>
            <div class="box" v-for="(imet,index) in arr" :key="imet.id" @click="gain(index)">
                <img :src="imet.url" alt="">
                <h2>{{imet.name}}</h2>
                <div>
                    <h6 class="sp2">{{imet.sale}}</h6>
                    <h6 class="sp1">{{imet.price | filtration}}</h6>
                </div>
            </div>
        </div>
    </template>
    <script>
        const app = new Vue({
            el: "#app",
            data() {
                return {}
            },
            components: {
                'box': {
                    template: "#box",
                    data() {
                        return {
                            arr: [{
                                    id: 1,
                                    name: "Redmi Note 11T Pro+",
                                    price: 2099,
                                    sale: "满减",
                                    url: "./img/1.webp"
                                },
                                {
                                    id: 2,
                                    name: "Redmi Note 11T Pro",
                                    price: 2199,
                                    sale: "满减",
                                    url: "./img/2.webp"
                                },
                                {
                                    id: 3,
                                    name: "Redmi Note 11SE",
                                    price: 2299,
                                    sale: "满减",
                                    url: "./img/3.webp"
                                },
                                {
                                    id: 4,
                                    name: "Xiaomi Civi 1S",
                                    price: 3099,
                                    sale: "满减",
                                    url: "./img/4.webp"
                                },
                                {
                                    id: 5,
                                    name: "Xiaomi Watch S1",
                                    price: 249,
                                    sale: "包邮",
                                    url: "./img/5.webp"
                                },
                                {
                                    id: 6,
                                    name: "Xiaomi真无线降噪耳机3",
                                    price: 1099,
                                    sale: "包邮",
                                    url: "./img/6.webp"
                                },
                                {
                                    id: 7,
                                    name: "Redmi手表2",
                                    price: 299,
                                    sale: "包邮",
                                    url: "./img/7.webp"
                                },
                                {
                                    id: 8,
                                    name: "小手环6 NFC版",
                                    price: 399,
                                    sale: "包邮",
                                    url: "./img/8.webp"
                                },
                                {
                                    id: 9,
                                    name: "小米电视",
                                    price: 2099,
                                    sale: "上新",
                                    url: "./img/9.webp"
                                },
                                {
                                    id: 10,
                                    name: "小米电视6至尊版65英寸",
                                    price: 4099,
                                    sale: "上新",
                                    url: "./img/10.webp"
                                }
                            ],
                            num: ""
                        }
                    },
                    methods: {
                        gain(i) {
                            this.num = this.arr[i].name
                        }
                    },
                    filters: {
                        filtration(val) {
                            return "￥" + val
                        }
                    }
                }
            },
            methods: {
                poiu() {
                    this.title = this.$children[0].num
                }
            }
        })
    </script>
</body>

</html>